package com.example.demo.service.Impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.bean.VoiceConfig;
import com.example.demo.mapper.VoiceConfigMapper;
import com.example.demo.service.VoiceConfigService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class VoiceConfigServiceImpl extends ServiceImpl<VoiceConfigMapper, VoiceConfig> implements VoiceConfigService {
    private final VoiceConfigMapper mapper;


    /** 切换默认音色 */
    @Override
    public void setDefault(Integer id) {
        mapper.update(null, Wrappers.<VoiceConfig>lambdaUpdate()
                .set(VoiceConfig::getIsDefault, false));
        mapper.update(null, Wrappers.<VoiceConfig>lambdaUpdate()
                .set(VoiceConfig::getIsDefault, true)
                .eq(VoiceConfig::getId, id));
    }

    @Override
    public VoiceConfig getDefault(Integer id) {
        return mapper.selectOne(Wrappers.<VoiceConfig>lambdaQuery()
                .eq(VoiceConfig::getIsDefault, true)
                .last("LIMIT 1"));
    }

    @Override
    public void update(VoiceConfig vo) {
        mapper.updateById(vo);
    }


    @Override
    public void deleteById(Integer id) {
        mapper.deleteById(id);
    }



}
